package org.devocean.groupbuying.service.impl;

import java.util.List;

import org.devocean.groupbuying.dao.CategoriesLocalizationDAO;
import org.devocean.groupbuying.dao.CategoryDAO;
import org.devocean.groupbuying.domain.CategoriesLocalization;
import org.devocean.groupbuying.domain.Category;
import org.devocean.groupbuying.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class CategoryServiceImpl implements CategoryService {

	@Autowired
	private CategoryDAO categoryDAO;

	@Autowired
	private CategoriesLocalizationDAO categoriesLocalizationDAO;

	@Transactional(readOnly = true)
	public List<Category> findAllCategorys() {
		return categoryDAO.findAllCategorys();
	}

	@Transactional(readOnly = true)
	public Category findCategoryById(Integer id) {
		return categoryDAO.findCategoryById(id);
	}

	@Transactional
	public void deleteCategory(Integer id, Integer categoryId) {
		CategoriesLocalization categoriesLocalization = categoriesLocalizationDAO
				.findCategoriesLocalizationById(id);
		if (categoriesLocalization != null)
			categoryDAO.deleteCategory(categoryId);

	}

	public List<Category> findCategoriesByCriteria(String criteria,
			Integer start, Integer size) {

		return categoryDAO.findCategoriesById(criteria, start, size);
	}

	public Long countCategoriesByCriteria(String criteria) {

		return categoryDAO.countCategoriesByCriteria(criteria);
	}

	public List<Category> getDisplayCategories(String lang) {

		return categoryDAO.findDisplayCategories(lang);
	}

}
